<div class="wrapper-bz-page">
    <div class="wrapper-bz-body">
        <div class="column-block block-left" style="width:400px;">
            <div class="column-title">数据表</div>
            <div class="column-content">
                <div class="column-filter">

                </div>
                <div class="column-datagrid">
                    <table id="table_datagrid_custom_in_m44" style="width:100%;height:100%"></table>
                </div>
            </div>
        </div>
        <div class="column-block block-right" style="left:410px;">
            <div class="column-block block-up">
                <div class="column-title">数据表相关列</div>
                <div class="column-content">
                    <div class="column-datagrid">
                        <table id="table_datagrid_column_in_m44" style="width:100%;height:100%"></table>
                    </div>
                </div>
            </div>
            <div class="column-block block-down">
                <div class="column-title">数据表工具栏</div>
                <div class="column-content">
                    <div class="column-datagrid no-filter">
                        <table id="table_datagrid_toolbar_in_m44" style="width:100%;height:100%"></table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div id="dialog_add_datagrid_custom_in_m44"></div>
<div id="dialog_edit_datagrid_custom_in_m44"></div>
<div id="dialog_add_datagrid_column_in_m44"></div>
<div id="dialog_edit_datagrid_column_in_m44"></div>
<div id="dialog_add_datagrid_toolbar_in_m44"></div>
<div id="dialog_edit_datagrid_toolbar_in_m44"></div>

<div id="dialog_bind_datagrid_column_in_m44"></div>
<script>
    $(function(){
        var subject_1 = "datagrid_custom_in_m44";
        var subject_2 = "datagrid_column_in_m44";
        var subject_3 = "datagrid_toolbar_in_m44";
        //列表-对话框-表单
        var tableId_1 = '#table_' + subject_1;
        var tableId_2 = '#table_' + subject_2;
        var tableId_3 = '#table_' + subject_3;

        var tableObject_1 = $(tableId_1);
        var tableObject_2 = $(tableId_2);
        var tableObject_3 = $(tableId_3);

        var addDialogId_1 = '#dialog_add_' + subject_1;
        var addDialogId_2 = '#dialog_add_' + subject_2;
        var addDialogId_3 = '#dialog_add_' + subject_3;

        var editDialogId_1 = '#dialog_edit_' + subject_1;
        var editDialogId_2 = '#dialog_edit_' + subject_2;
        var editDialogId_3 = '#dialog_edit_' + subject_3;

        var bindDialogId_2 = '#dialog_bind_' + subject_2;

        var addFormId_1 = '#form_add_' + subject_1;
        var addFormId_2 = '#form_add_' + subject_2;
        var addFormId_3 = '#form_add_' + subject_3;
        var editFormId_1 = '#form_edit_' + subject_1;
        var editFormId_2 = '#form_edit_' + subject_2;
        var editFormId_3 = '#form_edit_' + subject_3;
        var bindFormId_2 = '#form_bind_' + subject_2;

        var paramDataAdd_1 = {};
        var paramDataAdd_2 = {};
        var paramDataAdd_3 = {};
        var paramDataEdit_1 = {};
        var paramDataEdit_2 = {};
        var paramDataEdit_3 = {};

        var selectLeftMainId = 0;
        var configDialogAdd_1 = {
            href:'/admin/DatagridCustom/pageAdd',
            title:'新增数据表',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataAdd_1 = $(addFormId_1).serializeObject();
                    if(!paramDataAdd_1.datagrid_name){
                        layer.msg("请填写数据表名称");
                        return ;
                    }

                    if(!paramDataAdd_1.menu_id){
                        layer.msg("请选择菜单");
                        return ;
                    }
                    if(!paramDataAdd_1.table_id){
                        layer.msg("请选择数据表");
                        return ;
                    }

                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridCustom/addDatagridCustom',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataAdd_1,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(addDialogId_1).dialog('close');
                                $(tableId_1).datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_1).dialog('close');
                }
            }]
        };

        var configDialogAdd_2 = {
            href:'/admin/DatagridColumn/pageAdd',
            title:'新增数据表纵列',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataAdd_2 = $(addFormId_2).serializeObject();
                    paramDataAdd_2 = $.extend(paramDataAdd_2, {datagrid_id:selectLeftMainId});

                    if(!paramDataAdd_2.column_name){
                        layer.msg("请填写列标识码");
                        return ;
                    }
                    if(!paramDataAdd_2.column_title){
                        layer.msg("请填写列名");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridColumn/addDatagridColumn',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataAdd_2,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(addDialogId_2).dialog('close');
                                $(tableId_2).datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_2).dialog('close');
                }
            }]
        };
        var configDialogAdd_3 = {
            href:'/admin/DatagridToolbar/pageAdd',
            title:'新增页面工具栏',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataAdd_3 = $(addFormId_3).serializeObject();
                    paramDataAdd_3 = $.extend(paramDataAdd_3, {datagrid_id:selectLeftMainId});
                    console.log(paramDataAdd_3);
                    if(!paramDataAdd_3.button_type){
                        layer.msg("请填写按钮类型");
                        return ;
                    }
                    if(!paramDataAdd_3.button_text){
                        layer.msg("请填写按钮名称");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridToolbar/addDatagridToolbar',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataAdd_3,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(addDialogId_3).dialog('close');
                                tableObject_3.datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_3).dialog('close');
                }
            }]
        };
        var configDialogEdit_1 = {
            href:'/admin/DatagridCustom/pageEdit',
            title:'修改数据表',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataEdit_1 = $(editFormId_1).serializeObject();
                    if(!paramDataEdit_1.datagrid_code){
                        layer.msg("请填写唯一标识码");
                        return ;
                    }
                    if(!paramDataEdit_1.datagrid_name){
                        layer.msg("请填写数据表名称");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url:'/api/DatagridCustom/editDatagridCustom',
                        type:'post',
                        data: paramDataEdit_1,
                        dataType:'json',
                        async:false,
                        success:function(resp){
                            layer.close(loading);
                            if(0 == resp.code){
                                layer.msg(resp.message);
                            }else{
                                $(editDialogId_1).dialog('close');
                                tableObject_1.datagrid('reload');
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(editDialogId_1).dialog('close');
                }
            }]
        };
        var configDialogEdit_3 = {
            href:'/admin/DatagridToolbar/pageEdit',
            title:'编辑页面工具栏',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    paramDataEdit_3 = $(editFormId_3).serializeObject();
                    console.log(paramDataEdit_3);
                    if(!paramDataEdit_3.button_type){
                        layer.msg("请填写类型");
                        return ;
                    }
                    if(!paramDataEdit_3.button_text){
                        layer.msg("请填写名称");
                        return ;
                    }
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridToolbar/editDatagridToolbar',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataEdit_3,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(editDialogId_3).dialog('close');
                                tableObject_3.datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(editDialogId_3).dialog('close');
                }
            }]
        };

        var configDialogBind_2 = {
            href:'/admin/DatagridColumn/pageBindDictionary',
            title:'绑定数据字典',
            queryParams:{},
            width:dialogDefaultWidth,
            height:dialogDefaultHeight,
            modal:true,
            buttons:[{
                text:'<i class="fa fa-check fa-btn-cls" style="color:green"></i>保存',
                plain:true,
                handler:function(){
                    var paramDataBind_2 = $(bindFormId_2).serializeObject();
                    var loading = layer.load(1, {
                        shade: [0.1,'#fff'] //0.1透明度的白色背景
                    });
                    $.ajax({
                        url: '/api/DatagridColumn/bindDictionary',
                        async: false,
                        dataType:'json',
                        type:'post',
                        data:paramDataBind_2,
                        success:function(resp){
                            layer.close(loading);
                            if( 1 == resp.code ){
                                $(bindDialogId_2).dialog('close');
                                $(tableId_2).datagrid('reload');
                            }else{
                                layer.msg(resp.message);
                            }
                        }
                    });
                }
            },{
                text:'<i class="fa fa-times fa-btn-cls" style="color:red"></i>取消',
                plain:true,
                handler:function(){
                    $(addDialogId_2).dialog('close');
                }
            }]
        };

        var configDatagrid_1 = {
            url:'/api/DatagridCustom/getDatagridCustomList',
            method: 'post',
            remoteSort:false,
            queryParams:{},
            pageList:[25,50,100],
            pageSize:25,
            pagination:true,
            clickToEdit:false,
            dblclickToEdit:false,
            singleSelect:true,
            checkOnSelect:true,
            selectOnCheck:true,
            rownumbers:false,
            striped:true,
            fitColumns:true,
            fit:true,
            frozenColumns:[[
                {field:'ck',title:'ck',checkbox:true},
            ]],
            columns:[[
                {field:'id',title:'ID',width:40,hidden:true},
                {field:'third_menu_name',title:'菜单位置',width:100, formatter: function (value, row, index) {
                    return row.second_menu_name + '/' + value;
                }},
                {field:'datagrid_name',title:'数据表名称',width:100},
            ]],
            loadFilter: function(data){
                return loadFilter(data, true);
            },
            onSelect: function(index, row){
                configDatagrid_2.queryParams = {datagrid_id:row.id};
                configDatagrid_3.queryParams = {datagrid_id:row.id};
                if(0 == selectLeftMainId){
                    //第一次初始化
                    tableObject_2.datagrid(configDatagrid_2).datagrid("enableCellEditing");
                    tableObject_3.datagrid(configDatagrid_3).datagrid("enableCellEditing");
                }else{
                    tableObject_2.datagrid(configDatagrid_2);
                    tableObject_3.datagrid(configDatagrid_3);
                }
                selectLeftMainId = row.id;
            },
            onClickRow: function(index, row){
                // console.log("enter click row");
                // selectLeftMainId = row.id;
                // configDatagrid_2.queryParams = {datagrid_id:row.id};
                // tableObject_2.datagrid(configDatagrid_2);
            },
            onCheck: function(index, row){
            },
            onUncheck: function(index, row){
            },
            rowStyler: function(index, row){
                if(row.role_user_id > 0 && selectRoleId > 0){
                    return 'background:#c6e9ff';
                }
            },
            onLoadSuccess: function(){
                tableObject_1.datagrid('selectRow', 0);
                // $(".datagrid-header-check").html("");
            },
            toolbar:[
                {
                    text:'<span class="tool-btn-refresh"><i class="fa fa-refresh"></i>刷新</span>',
                    plain:true,
                    handler:function(){
                        tableObject_1.datagrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-add"><i class="fa fa-plus"></i>新增</span>',
                    plain:true,
                    handler:function(){
                        $(addDialogId_1).dialog(configDialogAdd_1);
                    }
                },
                {
                    text:'<span class="tool-btn-edit"><i class="fa fa-pencil"></i>编辑</span>',
                    plain:true,
                    handler:function(){
                        var rows = tableObject_1.datagrid("getChecked");
                        if(0 == rows.length){
                            layer.msg("请勾选要编辑的数据");
                        }
                        configDialogEdit_1.queryParams = {id:rows[0].id};
                        $(editDialogId_1).dialog(configDialogEdit_1);
                    }
                }
            ]

        };
        var configDatagrid_2 = {
            url:'/api/DatagridColumn/getDatagridColumnList',
            method: 'post',
            remoteSort:false,
            queryParams:{},
            pageList:[30,50,100],
            pageSize:30,
            pagination:true,
            clickToEdit:false,
            dblclickToEdit:true,
            singleSelect:false,
            checkOnSelect:false,
            selectOnCheck:false,
            rownumbers:false,
            striped:true,
            frozenColumns:[[
                {field:'ck',title:'ck',checkbox:true},
                {field:'id',title:'ID',width:40,hidden:true},
                {field:'column_name',title:'列标识码',width:150},
                {field:'column_title',title:'列名',width:150, editor:'textbox'},
            ]],
            columns:[[
                {field:'column_width',title:'列宽',width:100, editor:'textbox'},
                {field:'element_type',title:'元素类型',width:100, editor:'textbox'},
                {field:'fix_position',title:'标题位置',width:100},
                {field:'sort',title:'排序',width:100, editor:'textbox'},
                {field:'dictionary_name_cn',title:'字典',width:100},
                {field:'is_in_add',title:'新增是否包含',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_in_add' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchBtn\" ></form>"
                        } else {
                            return "<form><input data-field='is_in_add' data-id=" + row.id + "  class=\"easyui-switchbutton switchBtn\"></form>"
                        }
                    }
                },
                {field:'is_in_edit',title:'编辑是否包含',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_in_edit' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchBtn\" ></form>"
                        } else {
                            return "<form><input data-field='is_in_edit' data-id=" + row.id + "  class=\"easyui-switchbutton switchBtn\"></form>"
                        }
                    }},
                {field:'is_require',title:'是否必填',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_require' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchBtn\" ></form>"
                        } else {
                            return "<form><input data-field='is_require' data-id=" + row.id + "  class=\"easyui-switchbutton switchBtn\"></form>"
                        }
                    }},
                {field:'is_sort',title:'是否支持排序',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_sort' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchBtn\" ></form>"
                        } else {
                            return "<form><input data-field='is_sort' data-id=" + row.id + "  class=\"easyui-switchbutton switchBtn\"></form>"
                        }
                    }},
                {field:'is_fix',title:'是否固定',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_fix' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchBtn\" ></form>"
                        } else {
                            return "<form><input data-field='is_fix' data-id=" + row.id + "  class=\"easyui-switchbutton switchBtn\"></form>"
                        }
                    }},
                {field:'is_hide',title:'是否隐藏',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_hide' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchBtn\" ></form>"
                        } else {
                            return "<form><input data-field='is_hide' data-id=" + row.id + "  class=\"easyui-switchbutton switchBtn\"></form>"
                        }
                    }},
                {field:'status',title:'状态',width:50, align: 'center', formatter: function (value, row, index) {
                        if (1 == value) {
                            return '<span class="cell cell-yes"></span>';
                        } else if (2 == value) {
                            return '<span class="cell cell-no"></span>';
                        }
                    }},
                {field:'create_time',title:'创建时间',width:100},
                {field:'update_time',title:'更新时间',width:100},
            ]],
            loadFilter: function(data){
                return loadFilter(data, true);
            },
            onCheck: function(row){
            },
            onUncheck: function(row){
            },
            onEndEdit: function(index, row, changes) { //在完成编辑但编辑器还没有销毁之前触发
                console.log("end edit:", index, row);
                if (JSON.stringify(changes) != '{}') {
                    var updateData = $.extend({id:row.id}, changes);
                    $.ajax({
                        url:'/api/DatagridColumn/simpleUpdateDatagridColumn',
                        type:'post',
                        data: updateData,
                        dataType:'json',
                        async:false,
                        success:function(resp){
                            if(0 == resp.code){
                                layer.msg(resp.message);
                            }else{
                                //tableObject_2.datagrid('updateRow', index);
                                tableObject_2.datagrid('reload');
                            }
                        }
                    });
                }
            },
            onLoadSuccess:function(){
                $(".switchBtn").switchbutton({
                    height: 18,
                    onText: "是",
                    offText: "否",
                    onChange: function(value){
                        var newValue = value ? 1:2;
                        var datagridColumnId = $(this).data("id");
                        var fieldName = $(this).data("field");
                        toggleDatagridColumnInfo(datagridColumnId, fieldName, newValue);
                    }
                })
            },
            toolbar:[
                {
                    text:'<span class="tool-btn-refresh"><i class="fa fa-refresh"></i>刷新</span>',
                    plain:true,
                    handler:function(){
                        tableObject_2.datagrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-add"><i class="fa fa-plus"></i>新增</span>',
                    plain:true,
                    handler:function(){
                        var rows = tableObject_1.datagrid("getChecked");
                        if(0 == rows.length){
                            layer.msg("请勾选要新增列的数据表");
                        }
                        $(addDialogId_2).dialog(configDialogAdd_2);
                    }
                },
                {
                    text:'<span class="tool-btn-edit"><i class="fa fa-pencil"></i>更新</span>',
                    plain:true,
                    handler:function(){
                        var rows = tableObject_2.datagrid("getChecked");
                        if(0 == rows.length){
                            layer.msg("请勾选要更新的数据");
                        }
                        var arrId = [];
                        $.each(rows, function(index, item){
                            arrId.push(item.id);
                        });
                        $.ajax({
                            url:'/api/DatagridColumn/synUpdateDatagridColumn',
                            type:'post',
                            data: {arr_id: arrId},
                            dataType:'json',
                            async:false,
                            success:function(resp){
                                if(0 == resp.code){
                                    layer.msg(resp.message);
                                }else{
                                    tableObject_2.datagrid('reload');
                                }
                            }
                        });
                    }
                },
                {
                    text:'<span class="tool-btn-sync"><i class="fa fa-long-arrow-down"></i>同步</span>',
                    plain:true,
                    handler:function(){

                        tableObject_1.datagrid('reload');
                        $.ajax({
                            url:'/api/DatagridColumn/synAddDatagridColumn',
                            type:'post',
                            data: {datagrid_id: selectLeftMainId},
                            dataType:'json',
                            async:false,
                            success:function(resp){
                                if(0 == resp.code){
                                    layer.msg(resp.message);
                                }else{
                                    configDatagrid_2.queryParams = {datagrid_id: selectLeftMainId};
                                    tableObject_2.datagrid(configDatagrid_2);
                                }
                            }
                        });

                    }
                },
                {
                    text:'<span class="tool-btn-delete"><i class="fa fa-trash"></i>删除</span>',
                    plain:true,
                    handler:function(){
                        var rows = tableObject_2.datagrid("getChecked");
                        if(0 == rows.length){
                            layer.msg("请勾选要删除的库表字段");
                            return false;
                        }

                        var arrId = [];
                        $.each(rows, function(index, item){
                            arrId.push(item.id);
                        });
                        var confirm = layer.confirm('你确定要删除?',{title:'执行操作',btn:['是','否']},function() {
                            $.ajax({
                                url: '/api/DatagridColumn/deleteMultiDatagridColumn',
                                type: 'post',
                                data: {arr_id: arrId},
                                dataType: 'json',
                                async: false,
                                success: function (resp) {
                                    layer.close(confirm);
                                    if (0 == resp.code) {
                                        layer.msg(resp.message);
                                    }
                                    tableObject_2.datagrid('reload');
                                }
                            });
                        });
                    }
                },
                {
                    text:'<span class="tool-btn-bind"><i class="fa fa-link"></i>绑定字典</span>',
                    plain:true,
                    handler:function(){
                        var rows = tableObject_2.datagrid("getChecked");
                        if(0 == rows.length){
                            layer.msg("请勾选要绑定字典的数据");
                        }
                        configDialogBind_2.queryParams = {id:rows[0].id};
                        $(bindDialogId_2).dialog(configDialogBind_2);
                    }
                }
            ]

        };
        var configDatagrid_3 = {
            url:'/api/DatagridToolbar/getDatagridToolbarOption',
            method: 'post',
            remoteSort:false,
            queryParams:{},
            pageList:[30,50,100],
            pageSize:30,
            pagination:false,
            clickToEdit:false,
            dblclickToEdit:true,
            singleSelect:false,
            checkOnSelect:false,
            selectOnCheck:true,
            rownumbers:false,
            striped:true,
            // fitColumns:true,
            // fit:true,
            frozenColumns:[[
                {field:'ck',title:'ck',checkbox:true},
                {field:'id',title:'ID',width:40,hidden:true},
                {field:'button_type',title:'类型',width:100, editor:'textbox'},
                {field:'button_text',title:'功能',width:60, editor:'textbox'},
                {field:'is_open_dialog',title:'有无弹窗',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_open_dialog' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchbtn-pagetoolbar\" ></form>"
                        } else {
                            return "<form><input data-field='is_open_dialog' data-id=" + row.id + "  class=\"easyui-switchbutton switchbtn-pagetoolbar\"></form>"
                        }
                    }},
                {field:'is_confirm',title:'是否确认',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='is_confirm' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchbtn-pagetoolbar\" ></form>"
                        } else {
                            return "<form><input data-field='is_confirm' data-id=" + row.id + "  class=\"easyui-switchbutton switchbtn-pagetoolbar\"></form>"
                        }
                    }},
                {field:'status',title:'状态',width:100, formatter: function (value, row, index) {
                        if (value == 1) {
                            return "<form><input data-field='status' data-id=" + row.id + "  checked  class=\"easyui-switchbutton switchbtn-pagetoolbar\" ></form>"
                        } else {
                            return "<form><input data-field='status' data-id=" + row.id + "  class=\"easyui-switchbutton switchbtn-pagetoolbar\"></form>"
                        }
                    }},
            ]],
            columns:[[
                {field:'request_page_path',title:'页面路径',width:500, editor:'textbox'},
                {field:'request_api_path',title:'请求路径',width:500, editor:'textbox'},
                {field:'button_icon',title:'图标',width:100, editor:'textbox'},
                {field:'button_class',title:'样式类名',width:120, editor:'textbox'},
            ]],
            loadFilter: function(data){
                return loadFilter(data, false);
            },
            onClickRow: function(index, row){
                // console.log("enter click row");
                // selectLeftMainId = row.id;
                // configDatagrid_2.queryParams = {datagrid_id:row.id};
                // tableObject_2.datagrid(configDatagrid_2);
            },
            onCheck: function(index, row){
                var checkList = tableObject_3.datagrid('getChecked');
                if(checkList.length > 1){
                    $("#btn_edit_in_page_toolbar").linkbutton('disable');
                }else if(1 == checkList.length){
                    $("#btn_edit_in_page_toolbar").linkbutton('enable');
                    $("#btn_delete_in_page_toolbar").linkbutton('enable');
                }
            },
            onUncheck: function(index, row){
                var checkList = tableObject_3.datagrid('getChecked');
                if(checkList.length > 1){
                    $("#btn_edit_in_page_toolbar").linkbutton('disable');
                }else if(1 == checkList.length){
                    $("#btn_edit_in_page_toolbar").linkbutton('enable');
                    $("#btn_delete_in_page_toolbar").linkbutton('enable');
                }else{
                    $("#btn_edit_in_page_toolbar").linkbutton('disable');
                    $("#btn_delete_in_page_toolbar").linkbutton('disable');
                }
            },
            onEndEdit: function(index, row, changes) { //在完成编辑但编辑器还没有销毁之前触发
                if (JSON.stringify(changes) != '{}') {
                    var updateData = $.extend({id:row.id}, changes);
                    $.ajax({
                        url:'/api/DatagridToolbar/simpleUpdateDatagridToolbar',
                        type:'post',
                        data: updateData,
                        dataType:'json',
                        async:false,
                        success:function(resp){
                            if(0 == resp.code){
                                layer.msg(resp.message);
                            }else{
                                tableObject_3.datagrid('reload');
                            }
                        }
                    });
                }
            },
            onLoadSuccess: function(){
                $("#btn_edit_in_page_toolbar").linkbutton('disable');
                $("#btn_delete_in_page_toolbar").linkbutton('disable');
                $(".switchbtn-pagetoolbar").switchbutton({
                    height: 18,
                    onText: "是",
                    offText: "否",
                    onChange: function(value){
                        var newValue = value ? 1:2;
                        var pageToolbarId = $(this).data("id");
                        var fieldName = $(this).data("field");
                        togglePageToolbar(pageToolbarId, fieldName, newValue);
                    }
                })
            },
            toolbar:[
                {
                    text:'<span class="tool-btn-refresh"><i class="fa fa-refresh"></i>刷新</span>',
                    plain:true,
                    handler:function(){
                        tableObject_3.datagrid('reload');
                    }
                },
                {
                    text:'<span class="tool-btn-add"><i class="fa fa-plus"></i>新增</span>',
                    plain:true,
                    handler:function(){
                        $(addDialogId_3).dialog(configDialogAdd_3);
                    }
                },
                {
                    text:'<span class="tool-btn-edit"><i class="fa fa-pencil"></i>编辑</span>',
                    plain:true,
                    handler:function(){
                        var checkList = getDatagridCheckedRowData(tableObject_3, "编辑");
                        if(!checkList){
                            return false;
                        }
                        configDialogEdit_3.queryParams = {id:checkList[0].id};
                        $(editDialogId_3).dialog(configDialogEdit_3);
                    }
                },
                {
                    text:'<span class="tool-btn-delete"><i class="fa fa-trash"></i>删除</span>',
                    plain:true,
                    handler:function(){
                        var arrCheckId = getDatagridCheckedRowId(tableObject_3, "删除");
                        if(!arrCheckId){
                            return false;
                        }
                        var confirm = layer.confirm('你确定要删除?',{title:'执行操作',btn:['是','否']},function(){
                            $.ajax({
                                url:'/api/DatagridToolbar/deleteMultiDatagridToolbar',
                                type:'post',
                                data: {"arr_id": arrCheckId},
                                dataType:'json',
                                success:function(resp){
                                    layer.close(confirm);
                                    if(1 == resp.code){
                                        tableObject_3.datagrid('reload');
                                    }else{
                                        layer.msg(resp.message);
                                    }
                                }
                            });
                        });
                    }
                }
            ]

        };
        tableObject_1.datagrid(configDatagrid_1);

        // SearchCombobox('search_input_user_in_role','table_user_in_role',function (val,name) {
        //     configDatagrid_1.queryParams = {};
        //     configDatagrid_1.queryParams[name] = val;
        //     if(selectRoleId){
        //         configDatagrid_1.queryParams['role_id'] = selectRoleId;
        //     }
        //     tableObject_1.datagrid(configDatagrid_1);
        // },['ck','ID']);

        function togglePageToolbar(pageToolbarId, fieldName, value)
        {
            console.log("update page toolbar", pageToolbarId);
            $.ajax({
                url:'/api/DatagridToolbar/toggleDatagridToolbar',
                type:'post',
                data: {id: pageToolbarId, field_name: fieldName, value:value},
                dataType:'json',
                async:false,
                success:function(resp){
                    if(0 == resp.code){
                        layer.msg(resp.message);
                    }
                }
            });
        }

        function toggleDatagridColumnInfo(datagridColumnId, fieldName, value)
        {
            console.log("update page toolbar", datagridColumnId);
            $.ajax({
                url:'/api/DatagridColumn/toggleDatagridColumn',
                type:'post',
                data: {id: datagridColumnId, field_name: fieldName, value:value},
                dataType:'json',
                async:false,
                success:function(resp){
                    if(0 == resp.code){
                        layer.msg(resp.message);
                    }
                }
            });
        }

    });


</script>
